package com.directv.engineertools

import org.grails.plugins.excelimport.*

class ChannelExcelImporter extends AbstractExcelImporter {

	static Map propertyConfigurationMap = [
		authorName:([expectedType: ExpectedPropertyType.StringType, defaultValue:null]),
		numSold:([expectedType: ExpectedPropertyType.StringType, defaultValue:0]),
		('bookType'):[expectedType: ExpectedPropertyType.StringType, defaultValue:null, valueEquivalentToNull:'Select One'],
	]

	static Map CONFIG_BOOK_CELL_MAP = [
		sheet:'Sheet2',
		cellMap: [ 'D3':'title',
			'D4':'author',
			'D6':'numSold',
		]
	]

	static Map CONFIG_CHANNEL_COLUMN_MAP = [
		sheet:'Sheet1',
		startRow: 2,
		columnMap:  [
			'A':'providerID',
			'C':'providerName',
			'D':'channelNumber',
		]
	]

	//can also configure injection in resources.groovy
	def getExcelImportService() {
		ExcelImportService.getService()
	}

	public ChannelExcelImporter(fileName) {
		super(fileName)
	}

	List<Map> getChannels() {
		List channelList = excelImportService.columns(workbook, CONFIG_CHANNEL_COLUMN_MAP)
	}


	Map getOneMoreBookParams() {
		Map bookParams = excelImportService.cells(workbook, CONFIG_BOOK_CELL_MAP )
	}

	static void main(args) {
		//*****Practice Groovy*****
		println "Hello World"

		//---Weak Typing
		def a = 'John Du'
		a = new Object()
		a = 11
		println a

		//---String
		def firstName = 'John'
		def lastName = 'Du'
		def b = 7
		println "${lastName}, ${firstName}"
		println "a+b = ${a+b}"
		println '${lastName}, ${firstName}'
		println 'a+b = ${a+b}'

		//---List
		List javaList = new ArrayList()		//Java
		def groovyList = []					//Groovy
		def alist =[5, 1, 3, 5]
		//Contents are not strongly typed
		def myList = [
			10,
			"John",
			new Integer(5),
			new Double(7.6d)
		]
		//println myList.collate{it}
		println myList.size()
		//Appending items
		alist << 7
		alist << 6
		println alist.collect{it}
		println alist.size()
		println alist.findAll{it % 2 == 0}
		println alist.collect{it*10}

		//---Maps - a list of key value pairs
		def emptyMap =[:]
		def mapWithValues = [fruit:'Apple', veggie:'Carrot']
		//ways to add
		mapWithValues['car'] = 'Setan'
		mapWithValues.put('book', 'Novels')
		mapWithValues << [pet: 'Dog']
		println mapWithValues
		println mapWithValues['fruit']
		println mapWithValues.'veggie'
		println mapWithValues.get('car')
	}

}
